<template>
  <!-- 医院档案列表 -->
  <div class="factory-assessment-box">
    <el-container class="factory-assessment-container">
      <!-- 搜索 -->

      <el-header height="auto">
        <m-search
          ref="SearchForm"
          label-width="66px"
          :data="indexSearchData"
          :submit-loading="submitLoading"
          @searchForm="searchForm"
          @resetForm="resetForm"
        />
      </el-header>
      <!-- <el-button
        style="width: 98px; height: 38px; margin: 0 0 0 1200px"
        size="mini"
        type="primary"
        plain
        @click.stop="toSyncFiles()"
        >同步档案</el-button
      > -->
      <!-- 列表 -->
      <m-editable
        v-loading="tableLoading"
        style="margin: 0 20px"
        :empty-type="resultType"
        :data="dataList"
        height="400"
        :columns="columnsTable"
      >
        <template slot="default-hospitalNature" slot-scope="scope">
          {{
            scope.row.hospitalNature === 1
              ? '公立'
              : scope.row.hospitalNature === 2
              ? '民营'
              : scope.row.hospitalNature === 3
              ? '其他'
              : ''
          }}
        </template>
        <template slot="default-action" slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            plain
            @click.stop="toDetails(scope.row)"
            >查看
          </el-button>
          <el-button
            size="mini"
            type="primary"
            plain
            @click.stop="toEdit(scope.row)"
            >编辑</el-button
          >
        </template>
      </m-editable>
      <!-- 分页模块 -->
      <el-pagination
        v-show="paging"
        class="pageBox"
        align="right"
        style="margin-top: 10px"
        :current-page="page.curPage"
        :page-sizes="PAGE_NUMBER"
        :page-size="page.size"
        :layout="PAGINATION_LAYOUT"
        :total="page.total"
        @size-change="sizeChange"
        @current-change="pageChange"
      />
    </el-container>
  </div>
</template>
<script>
/* eslint-disable */

import { PAGE_NUMBER, PAGINATION_LAYOUT } from '@const/common';
import {
  hospitalRecordsList,
  syncFiles,
  natureList,
} from '@api/hossyn-order-center';
import { indexSearchData, columnsTable } from './const';

export default {
  data() {
    return {
      indexSearchData,
      searchData: {}, // 搜索数据
      submitLoading: false,
      page: {
        curPage: 1,
        pageSize: PAGE_NUMBER[0],
        total: 0,
      },
      tableLoading: false,
      dataList: [],
      columnsTable,
      PAGE_NUMBER, // 页码数组
      PAGINATION_LAYOUT, // 页码功能布局
      cycleList: [],
      resultType: 0,
      paging: true, // 分页显隐
    };
  },
  created() {
    this.hospitalRecordsListInquire();
    this.buttonMethod();
  },
  mounted() {},
  methods: {
    buttonMethod() {
      const arr = [
        // { type: 'button', val: '返回', handle: this.back },
        { type: 'primary', val: '同步档案', handle: this.toSyncFiles },
      ];
      const btn = {
        type: 'btn',
        arr,
      };
      this.$store.commit('changeLayoutHandle', btn);
    },
    toSyncFiles() {
      this.tableLoading = true;
      this.$axios({
        url: syncFiles,
        method: 'post',
        data: {},
      })
        .then((res) => {})
        .finally((err) => {
          this.tableLoading = false;
        });
    },
    // // 医院性质
    // natureListMethod(){
    //   this.tableLoading = true
    //   this.$axios({
    //     url: natureList,
    //     method: 'post',
    //     data: {
    //       ...this.searchData,
    //       page: this.page.curPage,
    //       pageSize: this.page.pageSize,
    //     },
    //   })
    //     .then((res) => {
    //       // debugger
    //       console.log( indexSearchData[2],'000000000')

    //       indexSearchData[2].options = res.data.payload.map(item=>({
    //          code:item.code,
    //          name:item.name
    //       }))
    //       this.page.total = res.data.payload.totalElements
    //       if(this.page.total==0){
    //       this.paging=false
    //       }

    //     })
    //     .finally((err) => {
    //       this.tableLoading = false
    //     })
    // },
    // 获取医院档案列表
    hospitalRecordsListInquire() {
      this.tableLoading = true;
      this.$axios({
        url: hospitalRecordsList,
        method: 'post',
        data: {
          ...this.searchData,
          page: this.page.curPage,
          pageSize: this.page.pageSize,
        },
      })
        .then((res) => {
          this.dataList = res.data.payload.content || [];
          this.page.total = res.data.payload.totalElements;
          if (this.page.total == 0) {
            this.paging = false;
          }
        })
        .finally((err) => {
          this.tableLoading = false;
        });
    },

    // 查看详情
    toDetails(row) {
      this.$router.push({
        path: '/distributorSide/archivesManagement/examine',
        query: {
          hospitalCode: row.hospitalCode,
        },
      });
    },
    // 编辑
    toEdit(row) {
      this.$router.push({
        path: '/distributorSide/archivesManagement/examine/edit',
        query: {
          hospitalCode: row.hospitalCode,
          hospitalName: row.hospitalName,
          departCode: row.departCode,
        },
      });
    },

    // 搜索功能-点击查询
    searchForm(condition) {
      this.page.curPage = 1;
      this.searchData = condition;
      this.hospitalRecordsListInquire('search');
    },
    // 点击重置
    resetForm(condition) {
      this.page.curPage = 1;
      this.searchData = condition;
      this.hospitalRecordsListInquire();
    },
    // 页码更改
    sizeChange(size) {
      this.page.pageSize = size;
      this.hospitalRecordsListInquire();
    },
    // 切换不一样的页面,重置一切数据
    pageChange(curPage) {
      this.page.curPage = curPage;
      this.hospitalRecordsListInquire();
    },
  },
};
</script>
<style lang="less" scoped>
.factory-assessment-box {
  margin: 0 0 10px 0 !important;
  .factory-assessment-container {
    height: 100%;
    overflow: auto;
    .action-button-box {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 12px;
      padding: 0 20px;
    }
    .pageBox {
      margin: 0 20px !important;
      padding: 7px 26px 6px 0;
      border: 1px solid @cutOffRuleColor;
      border-top: none;
      border-radius: 0 0 3px 3px;
    }
  }
}
</style>
